%Q1
A=imread('ckt-board.jpg');
%median filter
B=imnoise(A,'salt & pepper');
imshow(B,[]);
figure,imshow(C,[]);
[M N]=size(C);
for i=2:M-1
    for j=2:N-1
        D=[B(i-1,j-1) B(i-1,j) B(i-1,j+1) B(i,j+1) B(i+1,j+1) B(i+1,j) B(i+1,j-1) B(i,j-1)];
        B(i,j)=median(D);
    end
end
figure,imshow(B,[]);

%average filter
C=imnoise(A,'salt & pepper');
F=ones(3,3)/9;
f=imfilter(C,F);
figure,imshow(f,[]);
%Here,averaging filter is not as effective as median filter


%Q2
G=imread('moonrock.png');

figure,imshow(G,[]);
F=fft2(G);
Fc=fftshift(F);
imshow(Fc,[]);
S=abs(Fc);


[M N]=size(G);
for i=1:M
    for j=1:N
        H(i,j)=sqrt(S(i,j));
    end
end
figure,imshow(H,[]);

D0=176;
D1=186;
for i=1:M
    for j=1:N
        D=sqrt((i-(M/2))^2+(j-(N/2))^2);
        if(D>D0 && D<D1)
            H(i,j)=1;
        else
            H(i,j)=0;
        end
    end
end
figure,imshow(H,[]);
I=(Fc.*H);
J=ifft2(ifftshift(I));
figure,imshow(real(J),[]);


